#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:Vergil
# datetime:2018/9/24 2:44
# software: PyCharm
import logging
import random
import time

import requests

logger = logging.getLogger('main.v_brush')


def play_start(file_id, headers):
    url = 'https://spoc.tfswufe.edu.cn/JiaoXue/CourseKnowledgePoint/PlayerRecordTime'
    time = random.randint(90, 300)
    datas = {'fileId': file_id, 'time': time}

    try:
        requests.post(url, data=datas, headers=headers)

    except Exception as e:
        logger.exception(e)


def play_finish(file_id, headers):
    url = 'https://spoc.tfswufe.edu.cn/JiaoXue/CourseKnowledgePoint/FinishedPlaying'
    datas = {'fileId': file_id}

    try:
        requests.post(url, data=datas, headers=headers)

    except Exception as e:
        logger.exception(e)


def main(file_id_lst, headers, course_id, class_id):
    # headers['Referer'] = 'https://spoc.tfswufe.edu.cn/JiaoXue/CourseKnowledgePoint/StudentKnowledgePointIndex?courseId=%s&classId=%s' % (
    #     course_id, class_id)

    for file_id in file_id_lst:
        play_start(file_id, headers)
        play_finish(file_id, headers)
        time.sleep(1)

    logger.info('>>>>>>视频刷完<<<<<<')
